package com.pirestupppai.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.utils.WeakReferenceHandler;

/**
 *  图片编辑，选择添加相册或者文字Dialog
 */

public class ImageEditAddDialog extends Dialog {
    private final int EDIT_ADD_IMAGE = 0x23;
    private final int EDIT_ADD_TEXT = 0x24;
    private Context mContext;
    private WeakReferenceHandler mHandler;
    private TextView mAddImageTv;
    private TextView mAddTextTv;
    private RelativeLayout mCloseLayout;

    public ImageEditAddDialog(Context context, WeakReferenceHandler handler) {
        super(context, R.style.CustomDialogStyle);
        this.mContext = context;
        this.mHandler = handler;

        setContentView(R.layout.dialog_image_edit_add);

        Window menuWindow = getWindow();
        menuWindow.getAttributes().width = mContext.getResources().getDisplayMetrics().widthPixels;
        menuWindow.setGravity(Gravity.BOTTOM);
        menuWindow.setWindowAnimations(R.style.BottomDialogAnimStyle);
        setCanceledOnTouchOutside(true);

        mAddImageTv = (TextView) this.findViewById(R.id.add_image);
        mAddTextTv = (TextView) this.findViewById(R.id.add_text);
        mCloseLayout = (RelativeLayout) this.findViewById(R.id.ps_close_layout);

        mAddImageTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mHandler.sendEmptyMessage(EDIT_ADD_IMAGE);
                dismiss();
            }
        });

        mAddTextTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mHandler.sendEmptyMessage(EDIT_ADD_TEXT);
                dismiss();
            }
        });

        mCloseLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}
